package com.xuetang9.fujian.socketdemo;

import java.io.*;
import java.net.Socket;

/**
 * @author: fujian
 * @description: 使用Socket进行域名解析，IP地址与端口的组合 有客户端和服务端
 * udp IP/TCP
 * @date: 2021/5/9 11:18
 * @version: V1.0
 * @package: com.xuetang9.fujian.socketdemo
 **/
public class WhoIsDemo {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("whois.internic.net",43);
        // 需要向服务端发送请求，

        InputStream inputStream = socket.getInputStream();
        OutputStream outputStream = socket.getOutputStream();
        // 向服务器发送请求域名的指令
        String command = "xuetang9.com\n";
        outputStream.write(command.getBytes());
        // 接收服务器发送的结果
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
        String line = null;

        while ((line = reader.readLine()) != null){
            System.out.println(line);
        }


        reader.close();
        outputStream.close();
        inputStream.close();
        socket.close();
    }
}
